//
//  AppDelegate.m
//  MoGuRadio
//
//  Created by dlios on 15/6/3.
//  Copyright (c) 2015年 mogu.com 蘑菇科技. All rights reserved.
//

#import "AppDelegate.h"
#import "AllPageViewController.h"
#import "RecommendPageViewController.h"
#import "RankPageViewController.h"
#import "MyRadioViewController.h"
#import "CollectPageViewController.h"
#import "YRSideViewController.h"
#import "LeftViewController.h"
#import "SearchPageViewController.h"
#import "UMSocial.h"   // 第三方分享
#import "UIColor+ColorWithHex.h"



@interface AppDelegate ()

@end

@implementation AppDelegate


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    [_window release];
    
    UITabBarController *tabBarVC = [[UITabBarController alloc] init];
    
//    self.window.rootViewController = tabBarVC;
    
    AllPageViewController *allVC = [[AllPageViewController alloc] init];
    
    // tabBar图片
    UIImage *allImage = [UIImage imageNamed:@"homehome@2x.png"];
    allImage = [allImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    allVC.tabBarItem.image = allImage;
    
    UIImage *allImage1 = [UIImage imageNamed:@"homehome2@2x.png"];
    allImage1 = [allImage1 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    allVC.tabBarItem.selectedImage = allImage1;
    
    allVC.title = @"首页";
    
    
    // 改变TabBar字体颜se
    [[UITabBarItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor grayColor], NSForegroundColorAttributeName, nil] forState:UIControlStateNormal];
    [[UITabBarItem appearance] setTitleTextAttributes:                                                         [NSDictionary dictionaryWithObjectsAndKeys:[UIColor colorWithHexString:@"#71C671" andAlpha:1.0],NSForegroundColorAttributeName, nil]forState:UIControlStateSelected];
    
    
    RecommendPageViewController *recommendVC = [[RecommendPageViewController alloc] init];
    recommendVC.title = @"推荐";
    
    UIImage *recommendImage = [UIImage imageNamed:@"present@2x.png"];
    recommendImage = [recommendImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    recommendVC.tabBarItem.image = recommendImage;
    
    UIImage *recommendImage1 = [UIImage imageNamed:@"present2@2x.png"];
    recommendImage1 = [recommendImage1 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    recommendVC.tabBarItem.selectedImage = recommendImage1;
    
    RankPageViewController *rankVC = [[RankPageViewController alloc] init];
    rankVC.title = @"排行榜";
    UIImage *rankImage = [UIImage imageNamed:@"plane@2x.png"];
    rankVC.tabBarItem.image = rankImage;
    UIImage *rankImage2 = [UIImage imageNamed:@"plane2@2x.png"];
    rankImage2 = [rankImage2 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    rankVC.tabBarItem.selectedImage = rankImage2;
    
    SearchPageViewController *searchVC = [[SearchPageViewController alloc] init];
    searchVC.title = @"搜索";
    UIImage *searchImage = [UIImage imageNamed:@"searchb@2x.png"];
    searchVC.tabBarItem.image = searchImage;
    
    UIImage *searchImage2 = [UIImage imageNamed:@"searchb2@2x.png"];
    searchImage2 = [searchImage2 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    searchVC.tabBarItem.selectedImage = searchImage2;
    
    CollectPageViewController *collectVC = [[CollectPageViewController alloc] init];
    collectVC.title = @"收藏";
    
    UIImage *collectImage = [UIImage imageNamed:@"stars@2x.png"];
    collectVC.tabBarItem.image = collectImage;
    UIImage *collectImage2 = [UIImage imageNamed:@"stars2@2x.png"];
    collectImage2 = [collectImage2 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    collectVC.tabBarItem.selectedImage = collectImage2;
    
    UINavigationController *naviAll = [[UINavigationController alloc] initWithRootViewController:allVC];
    naviAll.title = @"首页";
    
    UINavigationController *naviRecommend = [[UINavigationController alloc] initWithRootViewController:recommendVC];
    
    UINavigationController *naviRank = [[UINavigationController alloc] initWithRootViewController:rankVC];
    
    UINavigationController *naviMyRadio = [[UINavigationController alloc] initWithRootViewController:searchVC];
    
    UINavigationController *naviCollect = [[UINavigationController alloc] initWithRootViewController:collectVC];
    
    
    tabBarVC.viewControllers = @[naviAll, naviRecommend, naviRank, naviMyRadio, naviCollect];
    
    [allVC release];
    [recommendVC release];
    [rankVC release];
    [searchVC release];
    [collectVC release];
    [naviAll release];
    [naviCollect release];
    [naviMyRadio release];
    [naviRank release];
    [naviRecommend release];
    
    
#warning +++++++++++++++++++++++++LX
    YRSideViewController *yr = [[YRSideViewController alloc] init];
    LeftViewController *le = [[LeftViewController alloc] init];
    yr.rootViewController = tabBarVC;
    yr.leftViewController = le;
    self.window.rootViewController = yr;
    [tabBarVC release];
    [yr release];
    [le release];
    
    [UMSocialSnsService  applicationDidBecomeActive];
    //第三方分享
    [UMSocialData setAppKey:@"5575050667e58ec34700328a"];
    
    return YES;
}


- (void)dealloc
{
    [_window release];
    [super dealloc];
}


- (void)applicationWillResignActive:(UIApplication *)application {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
    // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
    // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}

- (void)applicationWillTerminate:(UIApplication *)application {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

@end
